//
//  LGEvaluationReportCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/7.
//

#import "LGEvaluationReportCell.h"
#import "SVGKit.h"
#import "SVGKImage.h"
#import "SVGKParser.h"

@interface LGEvaluationReportCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *scoreLabel;
/**   */
@property (nonatomic , strong)UILabel *unitLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGEvaluationReportCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"cover_url"])]];
    self.titleLabel.text = LGNSString(dataDic[@"scale_title"]);
    NSString *score = LGNSString(dataDic[@"score"]);
    self.scoreLabel.text = [score containsString:@"-9999"]?@"":score;
    self.timeLabel.text = [NSString stringWithFormat:@"完成时间：%@",LGNSString(dataDic[@"create_time"])];
    self.unitLabel.hidden = ([score containsString:@"-9999"] || score.length == 0)?YES:NO;
}


-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.scoreLabel];
    [self.baseView addSubview:self.unitLabel];
    [self.baseView addSubview:self.timeLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(10));
        make.top.equalTo(self.iconView).offset(viewPix(4));
        make.right.equalTo(self.baseView).offset(-viewPix(60));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.right.equalTo(self.baseView).offset(-viewPix(50));
    }];
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.unitLabel.mas_left).offset(-2);
        make.bottom.equalTo(self.unitLabel).offset(3);
    }];
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.baseView).offset(-2);
    }];
}


-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(8), Screen_W-viewPix(32), viewPix(74));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(12), viewPix(50), viewPix(50))];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _titleLabel;
}

-(UILabel *)scoreLabel{
    if(!_scoreLabel){
        _scoreLabel = [UILabel lableWithText:@"" colorString:@"#5DC3A1" textFont:LGFontWeight(20, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _scoreLabel;
}

-(UILabel *)unitLabel{
    if(!_unitLabel){
        _unitLabel = [UILabel lableWithText:@"分" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _unitLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"评估完成时间：" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _timeLabel.frame = CGRectMake(viewPix(16), kMaxY(self.iconView.frame)+viewPix(13), viewPix(270), viewPix(22));
    }
    return _timeLabel;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
